/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: support oom_kill_notify feaure
 * Author: heyuqiang <heyuqiang1@huawei.com>
 * Create: 2023-09-06
 */
#include <linux/rtos_oomkill_notifier.h>

static BLOCKING_NOTIFIER_HEAD(rtos_oom_notify);
int rtos_oom_notifier_register(struct notifier_block *nb)
{
	if (!nb) {
		pr_err("rtos_oom_notifier_register with NULL parameter\n");
		return -EINVAL;
	}
	return blocking_notifier_chain_register(&rtos_oom_notify, nb);
}
EXPORT_SYMBOL_GPL(rtos_oom_notifier_register);

int rtos_oom_notifier_unregister(struct notifier_block *nb)
{
	if (!nb) {
		pr_err("rtos_oom_notifier_unregister with NULL parameter\n");
		return -EINVAL;
	}
	return blocking_notifier_chain_unregister(&rtos_oom_notify, nb);
}
EXPORT_SYMBOL_GPL(rtos_oom_notifier_unregister);

void rtos_oom_kill_notify(pid_t *rtos_oomkill_pid)
{
	if (!rtos_oomkill_pid) {
		pr_err("rtos_oomkill_pid with NULL parameter\n");
		return;
	}
	blocking_notifier_call_chain(&rtos_oom_notify, 0, rtos_oomkill_pid);
}